Covariance and Contravariance: Connict without a Cause

نویسندگان

  • GIUSEPPE CASTAGNA
  • Giuseppe Castagna
چکیده

In type-theoretic research on object-oriented programming, the issue of \covariance versus con-travariance" is a topic of continuing debate. In this short note we argue that covariance and con-travariance appropriately characterize two distinct and independent mechanisms. The so-called contravariancerule correctly captures the subtyping relation (that relation which establishes which sets of functions can replace another given set in every context). A covariant relation, instead, characterizes the specialization of code (i.e., the deenition of new code which replaces old definitions in some particular cases). Therefore, covariance and contravariance are not opposing views, but distinct concepts that each have their place in object-oriented systems. Both can (and should) be integrated in a type-safe manner in object-oriented languages. We also show that the independence of the two mechanisms is not characteristic of a particular model but is valid in general, since covariant specialization is present in record-based models, although it is hidden by a deeciency of all existing calculi that realize this model. As an aside, we show that the &-calculus can be taken as the basic calculus for both an overloading-based and a record-based model. Using this approach, one not only obtains a more uniform vision of object-oriented type theories, but in the case of the record-based approach, one also gains multiple dispatching, a feature that existing record-based models do not capture.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Coviarance and Contravariance : Connict without a Cause Covariance and Contravariance: Connict without a Cause

In type theoretic research on object-oriented programming the \covariance versus con-travariance issue" is a topic of continuing debate. In this short note we argue that covari-ance and contravariance appropriately characterize two distinct and independent mechanisms. The so-called contravariance rule correctly captures the substitutivity, or subtyping relation (that establishes which sets of c...

متن کامل

Covariance and Contravariance:conflict without a Cause Covariance and Contravariance: Connict without a Cause

In type theoretic research on object-oriented programming the \covariance versus con-travariance issue" is a topic of continuing debate. In this short note we argue that covari-ance and contravariance appropriately characterize two distinct and independent mechanisms. The so-called contravariance rule correctly captures the substitutivity, or subtyping relation (that establishes which sets of c...

متن کامل

Covariance and Contravariance: a fresh look at an old issue

Twenty years ago, in an article titled “Covariance and contravariance: conflict without a cause”, I argued that covariant and contravariant specialization of method parameters in object-oriented programming had different purposes and deduced that, not only they could, but actually they should both coexist in the same language. In this work I reexamine the result of that article in the light of ...

متن کامل

Spécialisation et sous-typage : thème et variations

Class specialization is the most original feature of object orientation, but identifying it to subtyping leads to the well known covariance-contravariance controversy. Type safety requires contravariance while specialization needs covariance. This paper aims to precisely analyse this problem, to show how irreductible it is and the need for type errors. We show that many alternatives as multiple...

متن کامل

Covariance, Contravariance, and Synchronization Constraints

Object Orientation and concurrent progamming are a natural match. Objects correspond to processes in a concurrent program; a message from one object to another invoking a method of the latter, corresponds naturally to (message passing) interaction between processes in a concurrent program. Despite this close correspondence, progress in developing an OO approach to concurrency has been limited. ...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2007